package com.aternity.geolocations;

import com.aternity.common.geolocation.CountryBoundariesRTree;
import com.aternity.common.geolocation.ReverseGeoCodingDataAccess;
import com.aternity.common.geolocation.TableauNamesCache;
import com.aternity.system.common.csv.CSVRWFactoryImpl;

import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.Set;

/**
 * @author ddd
 * @since 12/18/13 5:46 PM
 */
public class JsiPg {




    public static void main(String[] args) throws Exception {

        final String aternityHome = System.getProperty("aternity.home");
        Path countryGeometryDataFile = FileSystems.getDefault().getPath(aternityHome, "geo_locations", "country.geom.csv");
        Path stateGeometryDataFile = FileSystems.getDefault().getPath(aternityHome, "geo_locations", "state.geom.csv");
        ReverseGeoCodingDataAccess reverseGeoCodingDataAccess = new ReverseGeoCodingDataAccess(CSVRWFactoryImpl.getInstance());
        reverseGeoCodingDataAccess.load(countryGeometryDataFile, stateGeometryDataFile);

        CountryBoundariesRTree boundariesRTree = reverseGeoCodingDataAccess.getBoundariesRTree();
        TableauNamesCache namesCache = reverseGeoCodingDataAccess.getNamesCache();


        Set<Integer> containingEntities = boundariesRTree.findContainingRegionalEntities(34.766, 32.066);
        for (Integer containingEntity : containingEntities) {
            System.out.println("-----------------");
            System.out.println(namesCache.getCountryName(containingEntity));
            System.out.println(namesCache.getStateName(containingEntity));
        }

    }
}
